<?php
//by willson 105328468@qq.com 2014/10/11
//index page interface

class log_model extends base_model {
	private $apps;
	private $acts;

	public function __construct() {
		$this->apps = array(
			"order" => "订单",
			"member" => "会员",
			"project" => "项目",
			"beautician" => "美容师",
			"beautyshop" => "门店",
			"meal" => "套餐",
			"recharge" => "充值",
			"setting" => "系统设置",
		);
		$this->acts = array(
			"delete" => "删除",
			"save" => "保存",
			"add" => "新增",
			"edit" => "编辑",
			"list" => "列表",
			"index" => "首页",
			"detail" => "详情",
		);
		parent::__construct();
	}

	//写入日志
	public function create() {
		$member_id = $this->member_id;
		$member_name = $this->member_name;
		$user_agent = (isset($_SERVER['HTTP_USER_AGENT']) && trim($_SERVER['HTTP_USER_AGENT'])) ? substr(trim($_SERVER['HTTP_USER_AGENT']), 0, 300) : '';
		$script_name = (isset($_SERVER['SCRIPT_NAME']) && trim($_SERVER['SCRIPT_NAME'])) ? substr(trim($_SERVER['SCRIPT_NAME']), 0, 50) : '';
		$query_string = (isset($_SERVER['QUERY_STRING']) && trim($_SERVER['QUERY_STRING'])) ? substr(trim($_SERVER['QUERY_STRING']), 0, 125) : '';
		$resolution = (isset($_GET['resolution']) && trim($_GET['resolution'])) ? trim($_GET['resolution']) : '';
		$channel = (isset($_GET['channel']) && trim($_GET['channel'])) ? trim($_GET['channel']) : '';
		$imei = (isset($_GET['imei']) && trim($_GET['imei'])) ? trim($_GET['imei']) : '';
		$platform = (isset($_GET['platform']) && trim($_GET['platform'])) ? trim($_GET['platform']) : '';
		$network = (isset($_GET['network']) && trim($_GET['network'])) ? trim($_GET['network']) : '';
		$app_version = (isset($_GET['app_version']) && trim($_GET['app_version'])) ? trim($_GET['app_version']) : '';
		$api_version = (isset($_GET['api_version']) && trim($_GET['api_version'])) ? trim($_GET['api_version']) : '';
		$mobile_version = (isset($_GET['mobile_version']) && trim($_GET['mobile_version'])) ? trim($_GET['mobile_version']) : '';
		$language = (isset($_GET['language']) && trim($_GET['language'])) ? trim($_GET['language']) : '';
		$sql = "INSERT INTO jf_log(member_id, member_name, script_name, query_string, app, act, user_agent, ip, resolution, channel, imei, platform, network, app_version, api_version, mobile_version, language, add_time) 
			VALUES('{$member_id}', '{$member_name}', '{$script_name}', '{$query_string}', '{$this->app}', '{$this->act}', '{$user_agent}', '".ip()."', '{$resolution}', '{$channel}', '{$imei}', '{$platform}', '{$network}', '{$app_version}', '{$api_version}', '{$mobile_version}', '{$language}', '".time()."')";
		//echo $sql;
		$this->db->query($sql);
	}

	public function convert_app_name($app) {
		if (array_key_exists($app, $this->apps)) {
			return $this->apps[$app];
		} else {
			return '';
		}
	}

	public function convert_act_name($act) {
		if (array_key_exists($act, $this->acts)) {
			return $this->acts[$act];
		} else {
			return '';
		}
	}
}
